<template>
  <div class="wrap-home">
    <div class="nav">
      <el-button
        type="primary"
        size="mini"
        @click="addModel"
      >新增字典模型</el-button>
      <el-button
        type="primary"
        size="mini"
        @click="exportFile"
      >导出模型文件</el-button>

    </div>

    <div class="wrap-home-mian">
      <div class="home-item">
        <homeDictionary
          @item="handleTtem"
          ref="homeDictionary"
        ></homeDictionary>
      </div>
      <div class="home-item">
        <homeDetail></homeDetail>
      </div>
    </div>
    <!-- 新建模型 -->
    <newModelDialog
      :isNewModelDialog.sync="isNewModelDialog"
      v-if="isNewModelDialog"
      @update="updateTree"
    ></newModelDialog>
  </div>
</template>

<script>
import newModelDialog from "./newModelDialog";
import homeDictionary from "./homeDictionary";
import homeDetail from "./homeDetail";
export default {
  name: "Home",
  data() {
    return {
      isNewModelDialog: false,
    };
  },
  components: {
    newModelDialog,
    homeDictionary,
    homeDetail,
  },
  created() {
    this._getInit();
  },
  methods: {
    // 初始化数据
    async _getInit() {
      let res = await this.$http.get("/dictionary/objectNames");
      this.$store.commit("setObjectNames", res.data);
    },
    updateTree(data) {
      this.$refs.homeDictionary.init(data);
    },
    addModel() {
      this.isNewModelDialog = true;
    },
    // 点击某一项
    handleTtem(item) {
      console.log(item);
    },
    // 导出模型文件
    exportFile() {
      let name = this.$route.query.name;
      window.open(
        'https://model.cn.utools.club' + `/dictionary/export?modelName=${name}`
      );
    },
  },
};
</script>

<style lang="scss">
.wrap-home {
  .nav {
    margin: 10px;
  }
  .wrap-home-mian {
    margin: 10px;
    height: calc(100vh - 60px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-column-gap: 10px;
    .home-item {
      border: 1px solid rgba($color: #000000, $alpha: 0.1);
      box-shadow: 2px 2px 10px rgba($color: #000000, $alpha: 0.2);
      height: 100%;
      overflow: auto;
    }
  }
}
</style>
